﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Panny.Data;
using System.ComponentModel;
namespace Model
{
    [DataObject()]
   public class CouponsData
    {
        [DataObjectMethod(DataObjectMethodType.Insert)]
        public int Insert(string corpID,string imageSrc,string title,string btime,string etime,string desc,string save)
        {
            using (SqlStoredProcedure insertion = new SqlStoredProcedure("Pro_Pan_Coupons_Insert"))
            {
                insertion.AddParameter("@CorpID", corpID);
                insertion.AddParameter("@Title", title);
                insertion.AddParameter("@ImageSrc",imageSrc);
                insertion.AddParameter("@BeginDate",btime);
                insertion.AddParameter("@EndDate",etime);
                insertion.AddParameter("@Desc",desc);
                insertion.AddParameter("@Save",save);
                return insertion.ExecuteNonQuery();
            }
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public DataSet SelectSingle(string couponID)
        {
            using (SqlStoredProcedure seletion = new SqlStoredProcedure("Pro_Pan_Coupons_SelectSingle"))
            {
                seletion.AddParameter("@CouponID", couponID);
                return seletion.GetDataset();
            }
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public DataSet SelectListByCorpID(string corpID)
        {
            string sql = "select Title,[ImageSrc],BeginDate,EndDate,[Save],Hits,[desc] from Coupons where (@CorpID=0 or CorpID=@CorpID)";
            using (SqlText seletion = new SqlText(sql))
            {
                seletion.AddParameter("@CorpID", corpID);
                return seletion.GetDataset();
            }
        }
    }
}
